package com.yhy;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;
import io.netty.handler.codec.Delimiters;
import io.netty.handler.codec.string.StringDecoder;
import io.netty.handler.codec.string.StringEncoder;


public class HelloServerInitializer extends ChannelInitializer<SocketChannel>{
    @Override
    protected void initChannel(SocketChannel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();

        // 以("\n")为结尾分割的 解码器
//        pipeline.addLast("framer",
//                new DelimiterBasedFrameDecoder(1024000, Delimiters.lineDelimiter()));


        // 注册两个InboundHandler，执行顺序为注册顺序，所以应该是Handler1 Handler2
        pipeline.addLast(new MyChannelInboundHandler1());
        pipeline.addLast(new MyChannelInboundHandler2());

        // 注册两个OutboundHandler，执行顺序为注册顺序的逆序，所以应该是 Handler2 Handler1
        ch.pipeline().addLast(new MyChannelOutboundHandler1());
        ch.pipeline().addLast(new MyChannelOutboundHandler2());
    }
}
